import argparse
from video_processing import convert_video_format, extract_audio, create_video_thumbnail, resize_video
from subtitle_detection import detect_sub

def main():
    parser = argparse.ArgumentParser(description="MP4 Tool for video processing and subtitle detection.")
    subparsers = parser.add_subparsers(dest='command')

    # Convert video format
    parser_convert = subparsers.add_parser('convert', help='Convert video format')
    parser_convert.add_argument('input_file', help='Input video file')
    parser_convert.add_argument('output_file', help='Output video file')
    parser_convert.add_argument('output_format', help='Output video format')

    # Extract audio
    parser_extract = subparsers.add_parser('extract_audio', help='Extract audio from video')
    parser_extract.add_argument('input_file', help='Input video file')
    parser_extract.add_argument('output_file', help='Output audio file')

    # Create video thumbnail
    parser_thumbnail = subparsers.add_parser('thumbnail', help='Create video thumbnail')
    parser_thumbnail.add_argument('input_file', help='Input video file')
    parser_thumbnail.add_argument('output_image', help='Output image file')
    parser_thumbnail.add_argument('--time', default="00:00:01", help='Time to take the thumbnail')

    # Resize video
    parser_resize = subparsers.add_parser('resize', help='Resize video')
    parser_resize.add_argument('input_file', help='Input video file')
    parser_resize.add_argument('output_file', help='Output video file')
    parser_resize.add_argument('width', type=int, help='Width of the output video')
    parser_resize.add_argument('height', type=int, help='Height of the output video')

    # Detect subtitles
    parser_detect_sub = subparsers.add_parser('detect_sub', help='Detect subtitles in video')
    parser_detect_sub.add_argument('input_file', help='Input video file')

    args = parser.parse_args()

    if args.command == 'convert':
        convert_video_format(args.input_file, args.output_file, args.output_format)
    elif args.command == 'extract_audio':
        extract_audio(args.input_file, args.output_file)
    elif args.command == 'thumbnail':
        create_video_thumbnail(args.input_file, args.output_image, args.time)
    elif args.command == 'resize':
        resize_video(args.input_file, args.output_file, args.width, args.height)
    elif args.command == 'detect_sub':
        detect_sub(args.input_file)

if __name__ == "__main__":
    main()